<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form >
                    <p:panel >
                        <f:facet name="header" >
                            <h:outputLabel value="BHT Income by Categories" ></h:outputLabel>
                        </f:facet>
                        <h:panelGrid columns="2" >
                            <h:outputLabel value="Discharge From : " ></h:outputLabel>
                            <p:calendar value="#{inwardReportController.fromDate}" navigator="true" pattern="dd MMMM yyyy hh:mm:ss a" ></p:calendar>
                            <h:outputLabel value="Discharge To : " ></h:outputLabel>
                            <p:calendar value="#{inwardReportController.toDate}" navigator="true" pattern="dd MMMM yyyy hh:mm:ss a" ></p:calendar>                            
                            <h:outputLabel value="Admission Type : " ></h:outputLabel>
                            <p:selectOneMenu  id="lstAdmissionType"   value="#{inwardReportController.admissionType}" >
                                <f:selectItem itemLabel="All Admission Types"/>
                                <f:selectItems  value="#{admissionTypeController.items}" var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name}"></f:selectItems>
                            </p:selectOneMenu>
                            <h:outputLabel value="BHT Type : " ></h:outputLabel>
                            <p:selectOneMenu   id="cmbBhtType" value="#{inwardReportController.paymentMethod}"  >
                                <f:selectItem itemLabel="All BHT Types" />                           
                                <f:selectItems value="#{enumController.paymentMethodForAdmission}" />
                            </p:selectOneMenu>
                            <h:outputLabel value="Credit Company : " ></h:outputLabel>
                            <p:selectOneMenu  id="lstCc"   value="#{inwardReportController.institution}" >
                                <f:selectItem itemLabel="All Credit Companies"/>
                                <f:selectItems  value="#{creditCompanyController.creditCompanies}" var="cc" 
                                                itemValue="#{cc}" itemLabel="#{cc.name}"></f:selectItems>
                            </p:selectOneMenu>



                        </h:panelGrid>
                        <p:panelGrid columns="3">
                            <p:commandButton ajax="false" value="Process By Created Date(Inward)" action="#{inwardReportController.fillProfessionalPaymentDone()}" onclick="onSubmitButton();"  ></p:commandButton>
                            <p:commandButton ajax="false" value="Process By Created Date(OPD)" action="#{inwardReportController.fillProfessionalPaymentDoneOPD()}" onclick="onSubmitButton();"  ></p:commandButton>
                            <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" onclick="onSubmitButton();" >
                                <pe:exporter type="xlsx" target="tb1,tb2,tb3" fileName="bht_income_by_categories"  />
                            </p:commandButton>
                            <p:commandButton value="Print" ajax="false" action="#" >
                                <p:printer target="gpBillPreview" ></p:printer>
                            </p:commandButton>

                        </p:panelGrid>
                        <p:panel id="gpBillPreview">
                            <f:facet name="header" >
                                <h:outputLabel value="Inward Doctor Payment Done Report - " ></h:outputLabel>
                                <h:outputLabel value=" From : " ></h:outputLabel>
                                <h:outputLabel value="#{inwardReportController.fromDate}" >
                                    <f:convertDateTime pattern="yyyy MM dd hh:mm:ss a" />
                                </h:outputLabel>
                                <h:outputLabel value=" - To : " ></h:outputLabel>
                                <h:outputLabel value="#{inwardReportController.toDate}" >
                                    <f:convertDateTime pattern="yyyy MM dd hh:mm:ss a" />
                                </h:outputLabel>
                            </f:facet>
                            <p:dataTable value="#{inwardReportController.billedBill}" var="billedBill" id="tb1">
                                <f:facet name="header">
                                    <h:outputLabel value="Billed Bill"></h:outputLabel>
                                </f:facet>

                                <p:column headerText="Payment Bill No" >
                                    <h:outputLabel value="#{billedBill.bill.insId}" ></h:outputLabel>
                                </p:column>
                                <p:column headerText="Bht No" >
                                    <h:outputLabel value="#{billedBill.paidForBillFee.bill.patientEncounter.bhtNo}" ></h:outputLabel>
                                </p:column>

                                <p:column headerText="Discharged At" >
                                    <h:outputLabel value="#{billedBill.paidForBillFee.bill.patientEncounter.dateOfDischarge}" >
                                        <f:convertDateTime pattern="dd/MM/yy hh:mm:ss a"/>
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Specility" >
                                    <h:outputLabel value="#{billedBill.paidForBillFee.staff.speciality.name}" ></h:outputLabel>
                                </p:column>    
                                <p:column headerText="Doctor" >
                                    <h:outputLabel value="#{billedBill.paidForBillFee.staff.person.nameWithTitle}" ></h:outputLabel>
                                </p:column>                         
                                <p:column headerText="Paid at"  >
                                    <h:outputLabel value="#{billedBill.bill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MM/yy hh:mm:ss a"/>
                                    </h:outputLabel>
                                    <br/>
                                    <h:panelGroup rendered="#{billedBill.bill.cancelled}" >
                                        <h:outputLabel style="color: red;" value="Cancelled at " />
                                        <h:outputLabel style="color: red;" rendered="#{billedBill.bill.cancelled}" value="#{billedBill.bill.cancelledBill.createdAt}" >
                                            <f:convertDateTime pattern="dd/MM/yy hh:mm:ss a"/>
                                        </h:outputLabel>
                                    </h:panelGroup>
                                </p:column>  
                                <p:column headerText="Paid by" >
                                    <h:outputLabel value="#{billedBill.bill.creater.webUserPerson.name}" >                                      
                                    </h:outputLabel>
                                    <br/>
                                    <h:panelGroup rendered="#{billedBill.bill.cancelled}" >
                                        <h:outputLabel style="color: red;" value="Cancelled at " />
                                        <h:outputLabel style="color: red;" rendered="#{billedBill.bill.cancelled}" value="#{billedBill.bill.cancelledBill.creater.webUserPerson.name}" >                                       
                                        </h:outputLabel>
                                    </h:panelGroup>
                                </p:column>
                                <p:column headerText="Department"  >
                                    <h:outputLabel value="#{billedBill.paidForBillFee.bill.toDepartment.name}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                </p:column>
                                <p:column headerText="Service Name"  >
                                    <h:outputLabel value="#{billedBill.paidForBillFee.billItem.item.name}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                </p:column>
                                <p:column headerText="Charges" styleClass="averageNumericColumn" >
                                    <h:outputLabel value="#{billedBill.netValue}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController.totalBilledBill}">
                                            <f:convertNumber pattern="#,##0.00"/>
                                        </h:outputLabel>
                                    </f:facet>

                                </p:column>
                            </p:dataTable>

                            <p:spacer height="20px"/>

                            <p:dataTable value="#{inwardReportController.cancelledBill}" var="cancelledBill" id="tb2">
                                <f:facet name="header">
                                    <h:outputLabel value="CancelledBill Bill"></h:outputLabel>
                                </f:facet>
                                <p:column headerText="Payment Bill No" >
                                    <h:outputLabel value="#{cancelledBill.bill.insId}" ></h:outputLabel>
                                </p:column>
                                <p:column headerText="Bht No" >
                                    <h:outputLabel value="#{cancelledBill.paidForBillFee.bill.patientEncounter.bhtNo}" ></h:outputLabel>
                                </p:column>

                                <p:column headerText="Discharged At" >
                                    <h:outputLabel value="#{cancelledBill.paidForBillFee.bill.patientEncounter.dateOfDischarge}" >
                                        <f:convertDateTime pattern="dd/MM/yy hh:mm:ss a"/>
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Specility" >
                                    <h:outputLabel value="#{cancelledBill.paidForBillFee.staff.speciality.name}" ></h:outputLabel>
                                </p:column>    
                                <p:column headerText="Doctor" >
                                    <h:outputLabel value="#{cancelledBill.paidForBillFee.staff.person.nameWithTitle}" ></h:outputLabel>
                                </p:column>                         
                                <p:column headerText="Paid at"  >
                                    <h:outputLabel value="#{cancelledBill.bill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MM/yy hh:mm:ss a"/>
                                    </h:outputLabel>                                    
                                </p:column>  
                                <p:column headerText="Paid by" >
                                    <h:outputLabel value="#{cancelledBill.bill.creater.webUserPerson.name}" >                                      
                                    </h:outputLabel>                                    
                                </p:column>    
                                <p:column headerText="Service Name"  >
                                    <h:outputLabel value="#{cancelledBill.paidForBillFee.billItem.item.name}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                </p:column>
                                <p:column headerText="Charges"  styleClass="averageNumericColumn">
                                    <h:outputLabel value="#{cancelledBill.netValue}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController.totalCancelledBill}">
                                            <f:convertNumber pattern="#,##0.00"/>
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                            </p:dataTable>

                            <p:spacer height="20px"/>

                            <p:dataTable value="#{inwardReportController.refundBill}" var="refundBill" id="tb3">
                                <f:facet name="header">
                                    <h:outputLabel value="Refund Bill"></h:outputLabel>
                                </f:facet>

                                <p:column headerText="Payment Bill No" >
                                    <h:outputLabel value="#{refundBill.bill.insId}" ></h:outputLabel>
                                </p:column>
                                <p:column headerText="Bht No" >
                                    <h:outputLabel value="#{refundBill.paidForBillFee.bill.patientEncounter.bhtNo}" ></h:outputLabel>
                                </p:column>

                                <p:column headerText="Discharged At" >
                                    <h:outputLabel value="#{refundBill.paidForBillFee.bill.patientEncounter.dateOfDischarge}" >
                                        <f:convertDateTime pattern="dd/MM/yy hh:mm:ss a"/>
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Specility" >
                                    <h:outputLabel value="#{refundBill.paidForBillFee.staff.speciality.name}" ></h:outputLabel>
                                </p:column>    
                                <p:column headerText="Doctor" >
                                    <h:outputLabel value="#{refundBill.paidForBillFee.staff.person.nameWithTitle}" ></h:outputLabel>
                                </p:column>                         
                                <p:column headerText="Paid at"  >
                                    <h:outputLabel value="#{refundBill.bill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MM/yy hh:mm:ss a"/>
                                    </h:outputLabel>                                    
                                </p:column>  
                                <p:column headerText="Paid by" >
                                    <h:outputLabel value="#{refundBill.bill.creater.webUserPerson.name}" >                                      
                                    </h:outputLabel>                                    
                                </p:column>    
                                <p:column headerText="Service Name"  >
                                    <h:outputLabel value="#{refundBill.paidForBillFee.billItem.item.name}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                </p:column>
                                <p:column headerText="Charges" styleClass="averageNumericColumn" >
                                    <h:outputLabel value="#{refundBill.paidForBillFee.feeValue}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>

                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController.totalRefundBill}">
                                            <f:convertNumber pattern="#,##0.00"/>
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                            </p:dataTable>

                            <p:panelGrid columns="2" id="tb4">
                                <h:outputLabel value="Billed Bill Total"></h:outputLabel>
                                <h:outputLabel value="#{inwardReportController.totalBilledBill}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>

                                <h:outputLabel value="Cancelled Bill Total"></h:outputLabel>
                                <h:outputLabel value="#{inwardReportController.totalCancelledBill}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>

                                <h:outputLabel value="Refund Bill Total"></h:outputLabel>
                                <h:outputLabel value="#{inwardReportController.totalRefundBill}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>

                                <h:outputLabel value="Net Total"></h:outputLabel>
                                <h:outputLabel value="#{inwardReportController.totalBilledBill + inwardReportController.totalCancelledBill + inwardReportController.totalRefundBill}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                            </p:panelGrid>


                        </p:panel>


                    </p:panel>

                </h:form>
            </ui:define>

        </ui:composition>

    </h:body>
</html>
